package com.fzrskj.cloud.free.miniservice.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;

/**
 * JsonSnakeUtils.
 *
 * @author zj.
 *         Created on 2019/5/24 0024.
 */
public class JsonSnakeUtils {
    /**
     * 对像转下划线格式json
     * @param object 对象.
     * @return 转换后json数据.
     */
    public static String toJsonString(Object object) {
        ObjectMapper mapper = new ObjectMapper();
        mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
        try {
            return mapper.writeValueAsString(object);
        } catch (JsonProcessingException e) {
            return null;
        }
    }
}
